
package SOAPMisc;

import java.util.ArrayList;
import java.util.regex.Pattern;

import jxl.Workbook;

import utils.variable;

/**
 * Class used to store Gateways Information
 */
public class gwInfo
	{
	/**
	 * Variables
	 */
	private int index;
	private ArrayList<String[]> gwInfoList;
	
	
	/**
	 * Contructeur
	 */
	public gwInfo(int index)
		{
		/**
		 * Variables
		 */
		this.index = index;
		this.gwInfoList = new ArrayList<String[]>();
		}
	
	public int getIndex()
		{
		return index;
		}

	public ArrayList<String[]> getGwInfoList()
		{
		return gwInfoList;
		}
	

	/****************************************************************
	 * Method used to fill the gwInfoList :
	 * We add a String[] in the arraylist. This String[] contains
	 * 3 column :
	 * the first one represent : the unit
	 * the second one represent : the subunit
	 * the third one represent : is PRI port ? : 1=Yes 2=No 
	 ****************************************************************/
	public void fillGwInfoList(Workbook monWorkbook)
		{
		int a = 0;
		while(Pattern.matches(".*VWIC.*|.*VIC.*", monWorkbook.getSheet(2).getCell(a+18,index).getContents()))
			{
			if(Pattern.matches(".*VWIC3-2.*|.*VWIC2-2.*", monWorkbook.getSheet(2).getCell(a+18,index).getContents()))
				{
				gwInfoList.add(new String[]{Integer.toString(a),"0","1"});
				gwInfoList.add(new String[]{Integer.toString(a),"1","1"});
				}
			if(Pattern.matches(".*VWIC3-1.*|.*VWIC2-1.*", monWorkbook.getSheet(2).getCell(a+18,index).getContents()))
				{
				gwInfoList.add(new String[]{Integer.toString(a),"0","1"});
				}
			if(Pattern.matches(".*VIC2-2.*", monWorkbook.getSheet(2).getCell(a+18,index).getContents()))
				{
				gwInfoList.add(new String[]{Integer.toString(a),"0","0"});
				gwInfoList.add(new String[]{Integer.toString(a),"1","0"});
				}
			if(Pattern.matches(".*VIC2-1.*", monWorkbook.getSheet(2).getCell(a+18,index).getContents()))
				{
				gwInfoList.add(new String[]{Integer.toString(a),"0","0"});
				}
			a++;
			}
		}
	
	/****************************************************************
	 * Method used to fill the gwInfoList :
	 * We add a String[] in the arraylist. This String[] contains
	 * 3 column :
	 * the first one represent : the unit
	 * the second one represent : the subunit
	 * the third one represent : the Analog line Number
	 ****************************************************************/
	public void fillVGInfoList(Workbook monWorkbook)
		{
		if(Pattern.matches(".*202.*", monWorkbook.getSheet(2).getCell(2,index).getContents()))
			{
			for(int i=0; i<2; i++)
				{
				gwInfoList.add(new String[]{"0",Integer.toString(i),monWorkbook.getSheet(2).getCell(25+i,index).getContents(),""});
				}
			}
		if(Pattern.matches(".*204.*", monWorkbook.getSheet(2).getCell(2,index).getContents()))
			{
			for(int i=0; i<4; i++)
				{
				gwInfoList.add(new String[]{"0",Integer.toString(i),monWorkbook.getSheet(2).getCell(25+i,index).getContents(),""});
				}
			}
		if(Pattern.matches(".*224.*", monWorkbook.getSheet(2).getCell(2,index).getContents()))
			{
			for(int i=0; i<24; i++)
				{
				gwInfoList.add(new String[]{"2",Integer.toString(i),monWorkbook.getSheet(2).getCell(25+i,index).getContents(),""});
				}
			}
		/**
		 * Once gwInfoList is fill, we have to match DN with data in the sheet 0
		 */
		for(int i=0; i<gwInfoList.size(); i++)
			{
			if(!Pattern.matches("^$", gwInfoList.get(i)[2]))
				{
				int a=1;
				while(!Pattern.matches("#", monWorkbook.getSheet(0).getCell(7,a).getContents()))
					{
					if((Pattern.matches("Analog Device", monWorkbook.getSheet(0).getCell(4,a).getContents()))&&(Pattern.matches(gwInfoList.get(i)[2], monWorkbook.getSheet(0).getCell(7,a).getContents())))
						{
						gwInfoList.get(i)[3] = Integer.toString(a);
						}
					a++;
					}
				}
			}
		}
	
	
	/*2012*//*RATEL Alexandre 8)*/
	}
